// pages/h5test/h5test.js
let that
let tagName = 'h5test'
var socketTask
Page({

  /**
   * 页面的初始数据
   */
  data: {
    h5url: "http://www.baidu.com"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    that = this
    socketTask = wx.connectSocket({
      url: 'ws://125.121.87.43:10001/api/yx2-websocket/server',
      protocols: ['eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJwaG9uZVwiOlwiMTM5MDAwMDAwMDBcIixcImlmQWRtaW5cIjoxLFwidXNlclR5cGVcIjoxLFwiYXV0aFFPcGVuSWRcIjpcIk1pMHhOamsyT0RRek1ETTJOVEU1Smprd09EZ3dOelF3TnprNE1UazFOekV5TUE9PVwifSIsImlzcyI6IkF1dGhRIiwiZXhwIjoxNzA2NTcwNTcyLCJpYXQiOjE3MDI5NzA1NzIsImp0aSI6IjgyNjIxNjMzOTA0In0.MoS7ffRLccvDCXDunOOS_tE_np88xTIIcn2unLP680g'],
      success: (res) => {
        console.log(tagName, 'connect success', res)
      },
      fail: (err) => {
        console.log(tagName, 'connect fail', err)
      }
    })
    socketTask.onOpen(res => {
      console.log(tagName, 'onOpen', res, 'socketTask', socketTask)
    })
    socketTask.onMessage(res => {
      //data: "{"type":1000,"responseData":"{\"type\":1000,\"form\":\"h5\",\"modal\":\"scan\",\"params\":{\"a\":1,\"b\":2,\"c\":3}}"}"
      console.log(tagName, 'onMessage', res)
    })
    socketTask.onError(res => {
      console.log(tagName, 'onError', res)
    })
    socketTask.onClose(res => {
      console.log(tagName, 'onClose', res)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    socketTask.close()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})